﻿/*
 *	(*^。^*) TFrameWork License (*^。^*)
 */

/*
 *  Title : 轨道基类
 *
 *  Description :
 *  
 *
 *  Date :
 *
 *  Author : DengPing
 *
 *  Modify :
 */
using UnityEngine.UIElements;

namespace TFrameWork.Module.ActionEditor
{
    public enum TrackState
    {
        Normal = 0,
        Fold = 1 << 1, //折叠
        Disable = 1 << 2, //禁用
    }

    public abstract class TrackBase
    {
        /// <summary>
        /// 轨道名称
        /// </summary>
        protected abstract string trackName { get; }

        /// <summary>
        /// 信号轨道样式
        /// </summary>
        protected abstract TrackStyleBase _trackStyle { get; set; }

        /// <summary>
        /// 轨道状态
        /// </summary>
        public TrackState trackState = TrackState.Normal;


        /// <summary>
        /// 轨道菜单父节点
        /// </summary>
        public VisualElement menuParent;

        /// <summary>
        /// 轨道内容父节点
        /// </summary>
        public VisualElement trackParent;

        /// <summary>
        /// 轨道菜单序号
        /// </summary>
        public int index;


        public virtual void Init(VisualElement menuParent, VisualElement trackParent)
        {
            this.menuParent = menuParent;
            this.trackParent = trackParent;
            //初始化样式
            ResetLoadTrack();
        }

        /// <summary>
        /// 数据改变，重新绘制轨道内容
        /// </summary>
        public virtual void ResetLoadTrack()
        {

        }

        /// <summary>
        /// 删除子轨道
        /// </summary>
        /// <param name="frameIndex">子轨道序号</param>
        public virtual void DeleteTrackItem(int frameIndex)
        {
        }

        /// <summary>
        /// 配置修改
        /// </summary>
        public virtual void OnConfigChanged()
        {
        }

        /// <summary>
        /// 模拟播放
        /// </summary>
        /// <param name="startFrameIndex">当前的播放帧</param>
        public virtual void OnPlay(int startFrameIndex)
        {
        }

        /// <summary>
        /// 模拟运行
        /// </summary>
        /// <param name="frameIndex"></param>
        public virtual void TickPreView(int frameIndex)
        {
            _trackStyle.TickPreView(frameIndex);
        }



        public virtual void OnStop()
        {
        }

        /// <summary>
        /// 销毁轨道
        /// </summary>
        public virtual void Destroy()
        {
            if (_trackStyle != null)
            {
                _trackStyle.OnDestroy();
                _trackStyle = null;
            }
        }

        public virtual void DrawGizmos()
        {
            _trackStyle.DrawGizmos();
        }

        public virtual void OnSceneGUI()
        {
            _trackStyle.OnSceneGUI();
        }
    }
}
